package javabase;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ImplInvocationHandler implements InvocationHandler {
    
    private Object targetObj;
    public ImplInvocationHandler(Object obj) {
        this.targetObj = obj;
    }
    /**
     * @return
     * GY
     * 2017年11月6日
     */
    public Object getProxy(){
        return java.lang.reflect.Proxy.newProxyInstance(targetObj.getClass().getClassLoader(), 
                targetObj.getClass().getInterfaces(), 
                new ImplInvocationHandler(targetObj));
    }
    /*
     * 
     * 
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("Before invocation");
        Object retVal = method.invoke(targetObj, args);
        System.out.println("After invocation");
        return retVal; 
    }

}
